package com.bw.flinkstreaming.source.job3;
import org.apache.flink.api.common.functions.FilterFunction;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class FlinkWithParallelSource {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();


        //数据源
        DataStreamSource<Long> longDataStreamSource = env.addSource(new ParallelSource()).setParallelism(2);
        SingleOutputStreamOperator<Long> mapOprator = longDataStreamSource.map(new MapFunction<Long, Long>() {
            @Override
            public Long map(Long value) {
                System.out.println("接受到的数据：" + value);
                return value;
            }
        });
        SingleOutputStreamOperator<Long> filterOprator = mapOprator.filter(new FilterFunction<Long>() {
            @Override
            public boolean filter(Long value) {
                return value % 2 == 0;
            }
        });


        filterOprator.print().setParallelism(1);
        env.execute("FlinkWithParallelSource");
    }
}
